﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace mars_server.csharp.Util
{
    public class SqlUtil
    {
        public static string selectByPrimaryKey(string tableName,long id)
        {
            return "select * from " + tableName + " where " + tableName + ".`id` = " + id;
        }

        public static string delectByPrimaryKey(string tableName,long id)
        {
            return "delete from tableName where "+ tableName + ".`id` = " + id;
        }

        public static string selectByIds(string tableName,List<long> ids)
        {
            string query = "select * from " + tableName + " where " + tableName + ".`id` in (";
            foreach(long id in ids)
            {
                query = query + id + ",";
            }
            query = query + "0)";
            return query;
        }

        public static string selectByIntQuery(string tableName,string fieldName,string value)
        {
            return  "select * from " + tableName + " where " + tableName + ".`"+ fieldName + "` = " + value;
        }
        public static string selectByStringQuery(string tableName, string fieldName, string value)
        {
            return "select * from " + tableName + " where " + tableName + ".`" + fieldName + "` = \"" + value + "\"";
        }

        public static string selectByStringQueryRegexp(string tableName, string fieldName, string value)
        {
            return "select * from " + tableName + " where " + tableName + ".`" + fieldName + "` REGEXP  \"" + value + "\"";
        }
    }
}
